﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CPlatePrintSys.Application.ViewModels;
using CPlatePrintSys.Domain.Events;
using CPlatePrintSys.Win.ViewModels;
using MahApps.Metro.Controls;
using Prism.Events;
using Prism.Ioc;

namespace CPlatePrintSys.Win.Views
{
    /// <summary>
    /// AddBaseInfoView.xaml 的交互逻辑
    /// </summary>
    public partial class AddBaseInfoView : MetroWindow
    {
        private IEventAggregator _eventAggregator;

        public AddBaseInfoView()
        {
            InitializeComponent();

            _eventAggregator = (IEventAggregator)Prism.Ioc.ContainerLocator.Container.Resolve<IEventAggregator>();

            this.Loaded += AddBaseInfoView_Loaded;
            this.Closed += AddBaseInfoView_Closed;
        }

        private void AddBaseInfoView_Closed(object sender, EventArgs e)
        {
            _eventAggregator.GetEvent<WindowsPopupedEvent>().Publish(false);

        }

        private void AddBaseInfoView_Loaded(object sender, RoutedEventArgs e)
        {
            _eventAggregator.GetEvent<WindowsPopupedEvent>().Publish(true);


            if (DataContext is AddBaseInfoViewModel viewModel)
            {
                // Subscribe to RequestClose event
                viewModel.RequestClose += (result) =>
                {
                    this.DialogResult = result.Result == Prism.Dialogs.ButtonResult.OK;
                    this.Close();
                };
            }
        }
    }
}
